package com.viettel.rmsmobile;

import com.viettel.synctask.ApplyJobSyncTask;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class ApplyJobActivity extends Fragment {
	Spinner location;
	EditText currentSalary;
	EditText suggestSalary;
	Button btnApply;
	private Long recruitmentAnouncementId;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.apply_job, container, false);
		location = (Spinner) view.findViewById(R.id.location);
		currentSalary = (EditText) view.findViewById(R.id.currentSalary);
		suggestSalary = (EditText) view.findViewById(R.id.suggestSalary);
		btnApply = (Button) view.findViewById(R.id.btnApply);
		// Intent intent = getActivity().getIntent();
		// recruitmentAnouncementId =
		// intent.getLongExtra("recruitmentAnouncementId", -1L);
		recruitmentAnouncementId = getArguments().getLong(
				"recruitmentAnouncementId");
		btnApply.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				ApplyJobSyncTask applyJobSyncTask = new ApplyJobSyncTask(
						new ApplyJobActivity());
				applyJobSyncTask.execute(String
						.valueOf(recruitmentAnouncementId), currentSalary
						.getText().toString(), suggestSalary.getText()
						.toString(), "123");
			}
		});
		return view;
	}

	/**
	 * Thong bao ket qua
	 * 
	 * @param result
	 */
	public void notifyResult(String result) {
		if (result != null && result.equals("01")) {
			Toast.makeText(getActivity(), "Nộp đơn thành công !",
					Toast.LENGTH_SHORT).show();
		} else if (result != null && result.equals("03")) {
			Toast.makeText(getActivity(),
					"Lỗi ! Vị trí tuyển dụng đã được nộp đơn ",
					Toast.LENGTH_SHORT).show();
		} else {
			Toast.makeText(getActivity(), "Lỗi ! Nộp đơn thất bại ",
					Toast.LENGTH_SHORT).show();
		}
	}
}
